
import { _decorator, Component, Node, EditBox, Vec3, MeshCollider, ToggleContainerComponent, ToggleComponent } from 'cc';
import { MeshController, MeshTextureAlignType } from './MeshController';

const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = gameCtrl
 * DateTime = Wed May 25 2022 14:10:15 GMT+0800 (中国标准时间)
 * Author = qianqian2
 * FileBasename = gameCtrl.ts
 * FileBasenameNoExtension = gameCtrl
 * URL = db://assets/script/gameCtrl.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('gameCtrl')
export class gameCtrl extends Component {
    
    @property(EditBox)
  public  inputX1:EditBox = null;

  @property(EditBox)
  public  inputY1:EditBox = null;

  @property(EditBox)
  public  inputZ1:EditBox = null;


  @property(EditBox)
  public  inputX2:EditBox = null;

  @property(EditBox)
  public  inputY2:EditBox = null;

  @property(EditBox)
  public  inputZ2:EditBox = null;

  @property(MeshController)
  public cube1MeshController = null;

  @property(MeshController)
  public cube2MeshController = null;

  private inputValue:Vec3 = new Vec3(100,100,100);



  public  start () {
        // [3]  
        this.addEventListeners();
    }

public onDestroy(){
    this.removeEventListners();

}

    public addEventListeners(){
        this.inputX1.node.on('editing-did-ended', this.onEditBoxEndedX, this);
        this.inputY1.node.on('editing-did-ended', this.onEditBoxEndedY, this);
        this.inputZ1.node.on('editing-did-ended', this.onEditBoxEndedZ, this);

        this.inputX2.node.on('editing-did-ended', this.onEditBoxEndedX1, this);
        this.inputY2.node.on('editing-did-ended', this.onEditBoxEndedY1, this);
        this.inputZ2.node.on('editing-did-ended', this.onEditBoxEndedZ1, this);
    }

    public removeEventListners(){
        this.inputX1.node.off('editing-did-ended', this.onEditBoxEndedX1, this);
        this.inputY1.node.off('editing-did-ended', this.onEditBoxEndedY1, this);
        this.inputZ1.node.off('editing-did-ended', this.onEditBoxEndedZ1, this);

        this.inputX2.node.off('editing-did-ended', this.onEditBoxEndedX1, this);
        this.inputY2.node.off('editing-did-ended', this.onEditBoxEndedY1, this);
        this.inputZ2.node.off('editing-did-ended', this.onEditBoxEndedZ1, this);
    }

    //cube1 的输入监听
    private onEditBoxEndedX(editbox: EditBox) {
        this.inputValue.x = parseFloat(editbox.string);
        this.cube1MeshController.setScale(this.inputValue);
      
    }

    private onEditBoxEndedY(editbox: EditBox) {
        this.inputValue.y = parseFloat(editbox.string);
        this.cube1MeshController.setScale(this.inputValue);

        
    }

    private onEditBoxEndedZ(editbox: EditBox) {
        this.inputValue.z = parseFloat(editbox.string);
        this.cube1MeshController.setScale(this.inputValue);
     
    }



    //Cube2的输入监听
    
    private onEditBoxEndedX1(editbox: EditBox) {
        this.inputValue.x = parseFloat(editbox.string);
        this.cube2MeshController.setScale(this.inputValue);
      
    }

    private onEditBoxEndedY1(editbox: EditBox) {
        this.inputValue.y = parseFloat(editbox.string);
        this.cube2MeshController.setScale(this.inputValue);

        
    }

    private onEditBoxEndedZ1(editbox: EditBox) {
        this.inputValue.z = parseFloat(editbox.string);
        this.cube2MeshController.setScale(this.inputValue);
     
    }

    private onToggleGroup(toggle:ToggleComponent){
        // toggleContainer
        console.log('onToggleGroup====',toggle.node.name)
        if(toggle.node.name ==="Local"){
            this.cube1MeshController.setMeshTextureAlignType(MeshTextureAlignType.LOCAL);
            this.cube2MeshController.setMeshTextureAlignType(MeshTextureAlignType.LOCAL);

        }else{
            this.cube1MeshController.setMeshTextureAlignType(MeshTextureAlignType.WORLOD);
            this.cube2MeshController.setMeshTextureAlignType(MeshTextureAlignType.WORLOD);
        }

    }



}

